package com.kdgc.power.gen;


import org.beetl.core.Template;
import org.beetl.sql.clazz.kit.StringKit;
import org.beetl.sql.gen.Attribute;
import org.beetl.sql.gen.BaseProject;
import org.beetl.sql.gen.Entity;
import org.beetl.sql.gen.SourceConfig;
import org.beetl.sql.gen.simple.BaseTemplateSourceBuilder;

import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class MDSourceBuilder extends BaseTemplateSourceBuilder {
    /**
     * 指定模板的路径
     */
    public static  String entityPath = "md.btl";

    public MDSourceBuilder() {
        super("md");
    }

    @Override
    public void generate(BaseProject project,SourceConfig config, Entity entity) {
        List<String> commonNames= Arrays.asList( "modifyTime","createTime");
        Template template = groupTemplate.getTemplate(entityPath) ;
        ArrayList<Attribute> list = entity.getList();list.removeIf(attribute-> commonNames.contains( attribute.getName()));
        template.binding("attrs", entity.getList());
        template.binding("tableName", entity.getTableName());
        Writer writer = project.getWriterByName(this.name, StringKit.toLowerCaseFirstOne(entity.getName())+".md");
        template.renderTo(writer);



    }
}

